<script>
	// #ifdef APP-PLUS
	let device = uni.getSystemInfoSync().platform;
	let domain = "http://api.gdxixiashi.com/";
	// #endif
	// #ifdef MP-WEIXIN
	let domain = "https://wx.gdxixiashi.com/";
	// #endif
	export default {
		globalData:{ 
			domain:domain,
			imgDomain:domain,
			platform:uni.getSystemInfoSync().osName, // android  ios
			mapKey:'CYCBZ-FP2WZ-TNJXE-ZFJJR-N22Q6-ONBCR',
			userId:uni.getStorageSync('userId')?uni.getStorageSync('userId'):'',
			lat:'', 
			lng:'',  
			showCity:'',
			showAddress:''
		}, 
		onLaunch: function() {
			// #ifdef APP-PLUS
			// 处理版本号问题
			if(uni.getStorageSync('identify') && uni.getStorageSync('identify') == '1'){
				plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
					let verson = wgtinfo.versionCode;
					this.tool.getData("Regist/checkupdate",{}).then(res => {
						if (res) {
							let APP_banben = device=='android'?res.android_banben:res.ios_banben;
							let APP_url = device=='android'?res.android_url:res.ios_url;
							if (verson < APP_banben) {
								uni.showModal({
									title:'更新提示',
									content:'存在最新版本，是否现在更新?',
									success(res) {
										if(res.confirm){
											plus.runtime.openURL(APP_url);
										}
									} 
								})
							} else if (verson == APP_banben) {
								console.log("不用更新");
							}
						}
					}).catch(err => {
						console.log(err);
					})
				})
			}
			//app启动时打开启动广告页
			var w = plus.webview.open(
				'hybrid/html/advertise/advertise.html',
				'advertise', {
					top: 0,
					bottom: 0,
					zindex: 999
				},
				'fade-in',
				0
			);
			//设置定时器，4s后关闭启动广告页
			setTimeout(function() {
				plus.webview.close(w);
			}, 5000);
			uni.onPushMessage((res) => {  
				// 监听【在线、离线】通知栏消息的点击  
				if(res.type == 'click'){  
					// 如果需要跳转app内指定页面，则自己实现下方的跳转代码。  
					/* uni.navigateTo({       
						url:'指定页面路径'      
					}) */    
				}  
				// 监听【在线】消息到达。若云函数设置了 "force_notification":true，则不会触发此 receive。  
				if(res.type == 'receive'){  
					console.log("接收到的消息内容",res.payload);  
				}  
			})  
			plus.push.addEventListener(
				'receive',
				(msg) => {
					// 这是接收的内容
					console.log('recevice:' + JSON.stringify(msg))
					// 这里获取后端传来的参数
					console.log(JSON.parse(msg.content))
					let data=JSON.parse(msg.content);
					/* if(data.type==1){
						const innerAudioContext = uni.createInnerAudioContext();
						innerAudioContext.autoplay = true;
						innerAudioContext.src = 'https://www.gdxixiashi.com/public/order.mp3';
						innerAudioContext.onPlay(() => {
							console.log('开始播放');
						});
						innerAudioContext.onError((res) => {
							console.log('播放失败');
							console.log(res.errMsg);
							console.log(res.errCode);
						});
					} */
					
				},
				false
			)
			/* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送*/
			plus.push.addEventListener(
				'click',
				(msg) => {
					console.log('click:' + JSON.stringify(msg))
					/**
					 *  推送的标题/名字和内容
					 *  payload:{"title":"碎碎z","content":"聊天内容"}
					 */
					console.log(msg.payload)
				},
				false
			)
			
			// #endif
			// #ifdef MP-WEIXIN
			// 检查更新
			this.checkUpdate()
			// #endif
			if(!uni.getStorageSync('identify') || uni.getStorageSync('identify') == '1'){
				uni.setStorageSync('identify',1);
			}
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show');
			if(uni.getStorageSync('storeId')){
				let pages = getCurrentPages();
				// let currentRoute = pages[pages.length - 1].route;
				/* this.ws.init('storeId'+uni.getStorageSync('storeId'),(data)=>{
					if(data){
						this.$store.commit('changeCount',data.count);
						this.playAudo();
					}
				}) */
			}
		},
		onHide: function() {
			uni.removeStorageSync('toastCount');
		},
		methods:{
			async checkUpdate() {
			  // 1. 检查是否支持更新 API
			  if (!uni.getUpdateManager) return
			  
			  const updateManager = uni.getUpdateManager()
			  
			  // 2. 监听是否有更新
			  updateManager.onCheckForUpdate(res => {
				  console.log(res);
				if (res.hasUpdate) {
				  // 3. 监听更新下载完成
				  updateManager.onUpdateReady(() => {
					// 4. 强制更新逻辑
					uni.showModal({
					  title: '更新提示',
					  content: '新版本已准备好，需要重启应用',
					  showCancel: false, // 隐藏取消按钮
					  confirmText: '立即更新',
					  success: res => {
						if (res.confirm) {
						  // 5. 强制应用更新
						  updateManager.applyUpdate()
						}
					  }
					})
				  })
				  
				  // 6. 监听更新失败
				  updateManager.onUpdateFailed(() => {
					uni.showModal({
					  title: '更新失败',
					  content: '新版本下载失败，请检查网络',
					  showCancel: false
					})
				  })
				}
			  })
			},
			// 播放音频
			playAudo() {
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.autoplay = true;
				innerAudioContext.src = 'https://www.gdxixiashi.com/public/order.mp3';
				innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				innerAudioContext.onError((res) => {
					console.log('播放失败');
					console.log(res.errMsg);
					console.log(res.errCode);
				});
			},
		}
	}
</script>

<style lang='scss'>
	
	page {
		width: 100%;
		height: 100%;
		font-size: 14px;
		background: #F6F6F6;
		color: #333333;
	}

	button {
		background: none;
		padding: 0;
		margin: 0;
		border: none;
		line-height: normal;
		font-size: 14px;
	}

	button::after {
		border: none;
	}

	.and_pageTitle {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		height: calc(var(--status-bar-height) + 56px + 1px);

		.pageTitle {
			width: 100%;
			height: 46px;
			padding: 0 3%;
			box-sizing: border-box;
			margin-top: 10px;

			.backIcon {
				width: 40rpx;
			}

			.title {
				font-size: 16px;
				text-align: center;
				flex: 1;
				font-weight: bold;
			}
		}
	}

	.androidPadding {
		padding-top: calc(var(--status-bar-height) + 56px + 1px);
	}

	.ios_pageTitle {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0; 
		z-index: 99;
		height: calc(var(--status-bar-height) + 63px);

		.pageTitle {
			width: 100%;
			height: 44px;
			padding: 0 3%;
			margin-top: 18px;
			box-sizing: border-box;

			.backIcon {
				width: 40rpx;
			}

			.title {
				font-size: 16px;
			}
		}
	}

	.iosPadding {
		padding-top: calc(var(--status-bar-height) + 63px);
	}

	.statusBar {
		width: 100%;
		height: calc(var(--status-bar-height));
	}

	img {
		display: block;
		width: 100% !important;
	}

	image {
		height: auto;
		width: 100%;
		border-radius: 4px;
	}

	input,
	textarea {
		display: block;
		width: 100%;
	}

	.imgPublic {
		font-size: 0;
		overflow: hidden;
	}

	.dFlex {
		display: flex;
	}

	.jStart_aStart {
		justify-content: flex-start;
		align-items: flex-start;
	}

	.jStart_aCenter {
		justify-content: flex-start;
		align-items: center;
	}

	.jStart_aEnd {
		justify-content: flex-start;
		align-items: flex-end;
	}

	.jAround_aStart {
		justify-content: space-around;
		align-items: flex-start;
	}

	.jAround_aCenter {
		justify-content: space-around;
		align-items: center;
	}

	.jAround_aEnd {
		justify-content: space-around;
		align-items: flex-end;
	}

	.jCenter_aStart {
		justify-content: center;
		align-items: flex-start;
	}

	.jCenter_aCenter {
		justify-content: center;
		align-items: center;
	}

	.jCenter_aEnd {
		justify-content: center;
		align-items: flex-end;
	}

	.jEnd_aStart {
		justify-content: flex-end;
		align-items: flex-start;
	}

	.jEnd_aCenter {
		justify-content: flex-end;
		align-items: center;
	}

	.jEnd_aEnd {
		justify-content: flex-end;
		align-items: flex-end;
	}

	.jBetween_aStart {
		justify-content: space-between;
		align-items: flex-start;
	}

	.jBetween_aCenter {
		justify-content: space-between;
		align-items: center;
	}

	.jBetween_aEnd {
		justify-content: space-between;
		align-items: flex-end;
	}

	.flexDirection {
		flex-direction: column;
	}

	.fWap {
		flex-wrap: wrap;
	}

	.seat {
		height: 100px;
	}

	.zz {
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.5);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1000;
	}
	.whiteBg{
		background:rgba(255, 255, 255, 0.5);
	}

	.empty {
		width: 50% !important;
		margin: 80rpx auto 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	view::-webkit-scrollbar {
		display: none;
		/* Chrome Safari */
	}

	.ios_safe {
		padding-bottom: env(safe-area-inset-bottom) !important;
	}
	.commonTit{
		width: 100%;
		margin-bottom:12px;
		.tit{
			font-size: 13px;
			color: #333333;
			font-weight:bold;
		}
		.more{
			font-size: 12px;
			color: #999999;
		}
	}
</style>